﻿// ECommerce.ProductService.Entities/Product.cs
using Microsoft.EntityFrameworkCore;
using ProductService.Entities;
using System;
using System.ComponentModel.DataAnnotations;

namespace ECommerce.ProductService.Entities;

public class Product
{
    public Guid Id { get; set; }

    [Required]
    [MaxLength(100)]
    public string Name { get; set; } = string.Empty;

    public string Description { get; set; } = string.Empty;

    [Precision(18, 2)]
    public decimal Price { get; set; }

    public int StockQuantity { get; set; }

    // 外键：必须存在，且与Category.Id类型一致
    public Guid CategoryId { get; set; }

    // 导航属性：关键！必须是“可空类型（?）”且“无默认值（不写 = new()）”
    public Category? Category { get; set; } // ❗ 只能这样写，任何其他写法都可能报错

    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
}